<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    #myCanvas {
      border: 1px solid #ccc;
    }
    p, li {
      color: #666
    }
    .btns {
      margin-top: 20px;
      display: flex;
    }
    .btns button {
      margin-right: 10px;
    }
  </style>
  <title>fabric pen tool</title>
</head>
<body>
  <h1>Fabric-pen-tool Online Demo</h1>
  <canvas width="1000" height="600" id="myCanvas"></canvas>
  <div class="btns">
    <button id="btnOpen">Open</button>
    <button id="btnClose">Close</button>
    <button id="btnDestroy">Destroy</button>
  </div>
  <p>Tips:</p>
  <ol>
    <li>After opening, the graph cannot be selected. Click to draw a straight line, click and drag the animation of a quadratic Bezier curve (cubic Bezier curve is currently supported)</li>
    <li>The starting point is identified by a solid circle. When the mouse displays a closed circle icon at the starting point, clicking or dragging will close the graph</li>
    <li>You can continue selecting drawings after closing</li>  
  </ol>
  <script src="./public/fabric.min.js"></script>
  <script src="./dist/index.umd.js"></script>
  <script>
    const btnOpen = document.getElementById('btnOpen')
    const btnClose = document.getElementById('btnClose')
    const btnDestroy = document.getElementById('btnDestroy')
    const canvas = new fabric.Canvas('myCanvas')
    const pt = new fabricPenTool.PenTool(canvas)
    const ap = new fabric.Point(10, 20)
    const bp = new fabric.Point(18, 2)
    const distanceAB = ap.distanceFrom(bp);
    let delP = ap.subtract(bp)
    delP.setXY(Math.abs(delP.x), Math.abs(delP.y))

    btnOpen.onclick = function() {
      pt.open()
    }
    btnClose.onclick = function() {
      pt.close()
    }
    btnDestroy.onclick = function() {
      pt.destroy()
    }
    
  </script>
</body>
</html>